<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/coupons.css">
<link rel="stylesheet" href="skin/btn.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main" class="loading"></div>
</body>
<script>
	zy_init();
	var Users= new Users({});
	function sms(t){
		if (c_l()) {
			if (!localStorage['u_mobile']) {
				uexWindow.alert('错误提示', '请先在会员中心绑定手机号码~', '确定');
				return false;
			}
			var url = app_path + 'index.php?m=iappCoupons&c=app&a=lave&id=' + localStorage['coupons_id'] + '&userid=' + localStorage['u_id'] + '&acctoken=' + localStorage['u_acctoken'];
			uexXmlHttpMgr.open(1, 'post', url, "8000");
			uexXmlHttpMgr.send(1);
			uexWindow.toast(1, 5, '优惠码领取中...', 0);
		}else{
			gologin();
		}
	}
	
	function jump(id){
		localStorage['company_id']=id;
		uexWindow.open('company_show','0','company_show.html','2','', '',0);
	}
	
	function getMain(t){
		var url = app_path+'index.php?m=iappCoupons&c=app&a=show&id='+localStorage['coupons_id'];
		uexXmlHttpMgr.open(t,'post',url,"8000");
		uexXmlHttpMgr.send(t);
	}
			
	window.uexOnload=function(type){
		if(!type){
			uexWindow.setBounce("1");
			uexWindow.showBounceView("0","#666","0");
			uexWindow.showBounceView("1","#666","0");

			
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexXmlHttpMgr.close(opId);
				uexWindow.resetBounceView(opId);
				if(status==1){			
					data = JSON.parse(data);
					if(opId==-1){
						$$("main").className = '';
						if(data['status']=='OK'){
							var item=data['item'];
							var sd=new Date(item['start_time']*1000);
							var ed=new Date(item['end_time']*1000)
							var section='<div class="show">';
							section+='<div class="loadimg"><img src="'+item['picurl']+'" class="hide" onload="this.className=\'\'" /></div><h1>'+item['title']+'</h1>'+
							'<h2>'+item['title']+'</h2>'+
							'<pre class="min">有效期至'+sd.getFullYear()+'-'+(sd.getMonth()+1)+'-'+sd.getDate()+' 至 '+ed.getFullYear()+'-'+(ed.getMonth()+1)+'-'+ed.getDate()+'</pre>'+
							'<pre class="min" id="amount">领用数：'+item['lynum']+'　　剩余数量：'+item['lavenum']+'</pre>'+
							'<div class="btn pb" ><div class="button" onclick="sms(this);" >免费获取优惠券</div></div>'+
							'<h3>优惠详情</h3>'+
							'<h2 class="ltitle">'+item['ltitle']+'</h2>'+
							'<pre class="content">'+item['content']+'</pre>'+
							'<h3>使用须知</h3>'+
							'<pre class="precautions">'+item['Precautions']+'</pre>'+
							'<div class="btn pb" ><div class="button"  onclick="jump('+item['companyid']+');" >查看商家信息</div></div>'+
							'</div>';			
							$$("main").innerHTML=section;
						}else{
							uexWindow.alert('错误提示','该优惠券不存在','确定');
							uexWindow.evaluateScript('coupons_show',0,"uexWindow.close(-1);");
						}
					}
										
					if(opId==1){
						uexWindow.closeToast();
						if(data['status']=='OK'){
							uexWindow.alert('领取成功',data['msg'],'确定');
							$$('amount').innerHTML='领用数：'+data['data']['lynum']+'　　剩余数量：'+data['data']['lavenum'];
						}else if(data['status']=='NOLOGIN'){
							gologin();
						}else{
							uexWindow.alert('领取失败',data['msg'],'确定');
						}
					}
				}else if(status ==-1) {
					uexWindow.toast("0","5",'加载失败',2000);
				}
			}
			
			getMain(-1);
		}
	}
	</script>
</html>